﻿@using OA.Model;
@using OA.Model.View;
@using X.PagedList;
@using OA.Core.Helper;
@using OA.Core.Model;

@model PagedList<SimpleSynergyForm>
@{
    ViewBag.Title = "工作协作";
    Layout = "~/Areas/Member/Views/Shared/_Layout.cshtml";
    string empID = ViewBag.EmpID;
}
<div class="layui-tab layui-tab-brief" lay-filter="user">
    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 5px 0;">
        <form action="" class="layui-form">
            <div class="layui-form-item" style="margin: 10px 0 0;">
                <label class="layui-form-label" style="width: auto; padding-right: 5px;">协助主题：</label>
                <div class="layui-input-inline">
                    <input type="text" name="keywrod" class="layui-input" value="">
                </div>
                <button type="button" class="layui-btn searchButton">搜索</button><a class="layui-btn"  href="javascript:ShowPage('/Member/Synergy/Add','添加协作')">添加协作</a>                 
            </div>
        </form>
    </div>
    <table class="layui-table" lay-data="{url:'GetData', cellMinWidth: 80, page: true,limit:15}" id="resultList" lay-filter="resultList">
        <thead>
            <tr>
                <th lay-data="{field:'ID', width:70}">编号</th>
                <th lay-data="{field:'Name'}">协助主题</th>
                <th lay-data="{field:'StatusName', width:90}">状态</th>
                <th lay-data="{field:'LaunchDateTime', width:170}">发起时间</th>
                <th lay-data="{field:'EmpName', width:80}">发起人</th>
                <th lay-data="{field:'CurrentEditorName', width:110}">当前编辑人</th>
                <th lay-data="{fixed:'right', width:180, align:'center', toolbar: '#barDemo',width:400}">操作</th>
            </tr>
        </thead>
    </table>

    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="show" lay-data="{{d}}">查看</a>
        {{# if(d.EmpID=="@ViewBag.EmpID"){ }}

        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete" lay-data="{{d}}">删除</a>
        {{# } }}

        {{# if(d.EmpID=="@ViewBag.EmpID"||d.CurrentEditor=="@ViewBag.EmpID"||d.CurrentEditor=="") { }}

        {{# if(d.Status==1){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="Collaboration" lay-href="/Member/Synergy/Collaboration?id={{d.ID}}" lay-text="协作{{d.Name}}">协作</a>
        {{# } }}

        {{# if(d.CurrentEditor!=""&&d.CurrentEditor!=null){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Unlock" lay-data="{{d}}">解锁</a>
        {{# } }}
        {{# } }}


        {{# if(d.EmpID=="@ViewBag.EmpID"){ }}

        {{# if(d.Status==0){ }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" href="javascript:ShowPage('/Member/Synergy/Edit?id={{d.ID}}','修改{{d.Name}}',1)">修改</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="SponsorItem" lay-data="{{d}}">发起协作</a>
        {{# }else if(d.Status==1){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Finish" lay-data="{{d}}">完成</a>
        {{# }else if(d.Status==2){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="ReDo" lay-data="{{d}}">重新开启</a>
        {{# } }}
        {{# } }}
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="Clone" lay-data="{{d}}">克隆</a>

    </script>

</div>

<script type="text/javascript">

    layui.use(['table', 'element'], function () {
        var table = layui.table;
        table.on('tool(resultList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'show') {
                ShowPage('/Member/Synergy/Show/' + data.ID, data.Name, 0);
            }
            else if (obj.event === 'delete') {
                layer.confirm('<p>您正在进行删除工作协作操作</p><p style="color:red;">单据:' + data.Name + '</p>', {
                    title: "删除确认",
                    btn: ['是的,我要删除该工作协作', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/Delete", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("单据删除成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event === "Unlock") {
                layer.confirm('<p>您确认需要解锁当前单据的编辑锁定状态吗？</p><p style="color:red;">单据:' + data.Name+ '</p>', {
                    title: "解锁确认",
                    btn: ['是的,我要解锁', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/Unlock", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("解锁成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event === "SponsorItem") {
                layer.confirm('<p>您正在进行单据发起协作操作</p><p style="color:red;">单据:' + data.Name+ '</p>', {
                    title: "发起协作确认",
                    btn: ['是的,我要发起协作', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/SponsorItem", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("协作发起成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event === "Finish") {
                layer.confirm('<p>协作完成确认？</p><p style="color:red;">单据:' + data.Name + '</p>', {
                    title: "协作完成确认",
                    btn: ['是的,确认完成', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/Finish", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("确认完成成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event === "ReDo") {
                layer.confirm('<p>重新开启协作确认？</p><p style="color:red;">单据:' + data.Name + '</p>', {
                    title: "重新开启协作确认",
                    btn: ['是的,重新开启', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/ReDo", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("重新开启成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
            else if (obj.event == "Clone") {
                layer.confirm('<p>您确认需要克隆当前协作文档吗？</p><p style="color:red;">单据:' + data.Name + '</p>', {
                    title: "克隆确认",
                    btn: ['是的,我要克隆', '不小心点错了'] //按钮
                }, function () {
                    $.getJSON("/Member/Synergy/Clone", { id: data.ID }, function (result) {
                        if (result.State == 200) {
                            layer.msg("克隆成功!");
                            $(".layui-laypage-btn")[0].click();
                        }
                        else {
                            layer.msg(result.Message);
                        }
                    });
                }, function () {

                });
            }
        });
    });
 
</script>
